package july.android.cakes.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import july.android.cakes.service.SPoster;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * @author S_Cake
 * @version 校园活动
 */

@RestController
@EnableAutoConfiguration
public class CPoster {
    @Autowired
    private SPoster sv;
    
    @RequestMapping("/UP_poster")
    public void do_UPPoster(@RequestParam("imgURL") String pic, @RequestParam("team_id") String team_id, HttpServletResponse hp) throws IOException {
        sv.UPPoster(pic,team_id);
        //System.out.println(ttype);
        //System.out.println(detail);
        //System.out.println(tel);
        //System.out.println(imgURL);
        //System.out.println(stu_id);
        //hp.sendRedirect("http://123.206.198.158/back.html");
    }
    
    //根据传入的社团账号修改社团密码
    @RequestMapping("/update_passw")
    public void do_updatepassw(@RequestParam("id") String id,@RequestParam("passw") String passw)throws Exception{
        sv.updatepassw(id,passw);
    }

    // 根据传入的社团账号以及海报路径插入进校园新闻表，返回校园新闻号
    //根据前面一个方法即时获得的社团账号以及校园新闻号，再调用方法插入到社团与新闻的关联表中
    @RequestMapping("/add_news")
    public void do_addnews(@RequestParam("id") String id,@RequestParam("pic")String pic)throws Exception {
         sv.addnews(id,pic);
    }

     //显示全部的校园海报栏，返回头像路径和海报路径
    @RequestMapping("/get_news")
    public List<Map<String,Object>>  do_getnews()throws Exception{
        return sv.getnews();
    }

     //显示校方组织的校园海报栏，返回头像路径和海报路径
    @RequestMapping("/get_schoolnews")
    public List<Map<String,Object>>  do_getschoolnews()throws Exception{
        return sv.getschoolnews();
    }

     //显示学生组织的校园海报栏，返回头像路径和海报路径
    @RequestMapping("/get_studentnews")
    public List<Map<String,Object>>  do_getstudentnews()throws Exception{
        return sv.getstudentnews();
    }

    //根据传入的社团登录账号id,返回这个账号发布的所有海报id，组织头像，发布海报
    @RequestMapping("/get_my_news")
    public List<Map<String,Object>>  do_getmynews(@RequestParam("id") String id)throws Exception{
        return sv.getmynews(id);
    }
    
    //删除海报，删除成功后返回字符串，用于后台管理
    @RequestMapping("/remove_news")
    public String do_removenews(@RequestParam("id") String id){
        return sv.removenews(id);
    }
    //根据传入的社团账号，社团头像路径更新社团的头像
    @RequestMapping("/update_depimage")
    public void do_updatedepimage(@RequestParam("id") String id,@RequestParam("icon") String icon)throws Exception{
        sv.updatedepimage(id,icon);
    }


    
    //根据传入的社团账号获取社团的名字 
    @RequestMapping("/get_depName")
    public String do_getdep(@RequestParam("id") String id)throws Exception{
        return sv.getdepName(id);
    }
}
